<template>
  <div id="container"></div>
</template>

<script setup>
import { onMounted, onUnmounted } from "vue";
import { Chart } from "@antv/g2";

let chart;

onMounted(() => {
  chart = new Chart({
    container,
    autoFit: true,
  });

  chart
    .title('限制高度的柱形图')
    .interval()
    .data([
      { genre: "Sports", sold: 0 },
      { genre: "Strategy", sold: 115 },
      { genre: "Action", sold: 120 },
      { genre: "Shooter", sold: 350 },
      { genre: "Other", sold: 150 },
    ])
    .encode("x", "genre")
    .encode("y", "sold")
    .style({
      minHeight: 60
    });

  chart.render();
});

// 销毁
onUnmounted(() => {
  chart.destroy();
  chart = null;
});
</script>

<style lang="less" scoped>
#container {
  width: 800px;
  height: 400px;
}
</style>
